package com.example.permissionsystem1_1.businessFunction.controller.impl;

import com.example.permissionsystem1_1.businessFunction.controller.converter.DepartmentInfoControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.converter.UserInfoControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentInfoReqDto.*;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userInfoReqDto.*;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentInfoRspDto.*;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userInfoRspDto.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentInfoReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userInfoReqModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentInfoRspModel.*;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userInfoRspModel.*;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.DepartmentInfoService;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.UserInfoService;
import com.example.permissionsystem1_1.common.businessFunction.BaseController;
import com.example.permissionsystem1_1.common.util.RspResult;
import com.example.permissionsystem1_1.system.util.WebUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * 用户类
 * 后面这里的基础接口方法,都应该抽取成公共方法放到Base类中或者是用代码生成器生成模板代码(而不需要手写)
 */
@RestController
@RequestMapping("/userInfo")
@ApiModel("用户")
public class UserInfoController extends BaseController {
    @Autowired
    private UserInfoService userInfoService;
//    @ApiOperation(value = "测试", notes = "测试", httpMethod = "GET")
//    @RequestMapping(value = "/test1",method = RequestMethod.GET)
//    public String test1(){
//        return "test1";
//    }

    @ApiOperation(value = "新增一条记录", notes = "新增一条记录", httpMethod = "POST")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public RspResult<UserInfoInsertRspDto> insert(@Validated @RequestBody UserInfoInsertReqDto reqDto){
        UserInfoInsertReqModel reqModel= UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoInsertRspModel rspModel=userInfoService.insert(reqModel);
        UserInfoInsertRspDto rspDto= UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

//    @ApiOperation(value = "批量新增多条记录", notes = "批量新增多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/insertBatch",method = RequestMethod.POST)
//    public RspResult<TestInsertBatchRspDto> insertBatch(@Validated @RequestBody TestInsertBatchReqDto reqDto){
//        TestInsertBatchReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestInsertBatchRspModel rspModel=testService.insertBatch(reqModel);
//        TestInsertBatchRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

    @ApiOperation(value = "根据id删除一条记录", notes = "根据id删除一条记录", httpMethod = "POST")
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public RspResult<UserInfoDeleteByIdRspDto> deleteById(@Validated @RequestBody UserInfoDeleteByIdReqDto reqDto){
        UserInfoDeleteByIdReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoDeleteByIdRspModel rspModel=userInfoService.deleteById(reqModel);
        UserInfoDeleteByIdRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

//    @ApiOperation(value = "根据给定的字段值删除符合条件的多条记录", notes = "根据给定的字段值删除符合条件的多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/deletes",method = RequestMethod.POST)
//    public RspResult<TestDeletesRspDto> deletes(@Validated @RequestBody TestDeletesReqDto reqDto){
//        TestDeletesReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestDeletesRspModel rspModel=testService.deletes(reqModel);
//        TestDeletesRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

//    @ApiOperation(value = "根据id集合删除多条记录", notes = "根据id集合删除多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/deleteBatchByIds",method = RequestMethod.POST)
//    public RspResult<TestDeleteBatchByIdsRspDto> deleteBatchByIds(@Validated @RequestBody TestDeleteBatchByIdsReqDto reqDto){
//        TestDeleteBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestDeleteBatchByIdsRspModel rspModel=testService.deleteBatchByIds(reqModel);
//        TestDeleteBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

    @ApiOperation(value = "根据id修改一条记录", notes = "根据id修改一条记录", httpMethod = "POST")
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public RspResult<UserInfoUpdateByIdRspDto> updateById(@Validated @RequestBody UserInfoUpdateByIdReqDto reqDto){
        UserInfoUpdateByIdReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoUpdateByIdRspModel rspModel=userInfoService.updateById(reqModel);
        UserInfoUpdateByIdRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

//    @ApiOperation(value = "根据指定的byTestPo中的属性为选择条件,按照setTestPo中的属性进行修改符合条件的多条记录", notes = "根据指定的byTestPo中的属性为选择条件,按照setTestPo中的属性进行修改符合条件的多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/updates",method = RequestMethod.POST)
//    public RspResult<TestUpdatesRspDto> updates(@Validated @RequestBody TestUpdatesReqDto reqDto){
//        TestUpdatesReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestUpdatesRspModel rspModel=testService.updates(reqModel);
//        TestUpdatesRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

//    @ApiOperation(value = "根据指定多个ids,来批量修改多条记录", notes = "根据指定多个ids,来批量修改多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/updateBatchByIds",method = RequestMethod.POST)
//    public RspResult<TestUpdateBatchByIdsRspDto> updateBatchByIds(@Validated @RequestBody TestUpdateBatchByIdsReqDto reqDto){
//        TestUpdateBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestUpdateBatchByIdsRspModel rspModel=testService.updateBatchByIds(reqModel);
//        TestUpdateBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

    @ApiOperation(value = "根据指定id查询一条记录", notes = "根据指定id查询一条记录", httpMethod = "POST")
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public RspResult<UserInfoSelectByIdRspDto> selectById(@Validated @RequestBody UserInfoSelectByIdReqDto reqDto){
        UserInfoSelectByIdReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoSelectByIdRspModel rspModel=userInfoService.selectById(reqModel);
        UserInfoSelectByIdRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "根据指定的条件查询符合条件的多条记录", notes = "根据指定的条件查询符合条件的多条记录", httpMethod = "POST")
    @RequestMapping(value = "/selects",method = RequestMethod.POST)
    public RspResult<UserInfoSelectsRspDto> selects(@Validated @RequestBody UserInfoSelectsReqDto reqDto){
        UserInfoSelectsReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoSelectsRspModel rspModel=userInfoService.selects(reqModel);
        UserInfoSelectsRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

//    @ApiOperation(value = "根据多个id查询多条记录", notes = "根据多个id查询多条记录", httpMethod = "POST")
//    @RequestMapping(value = "/selectBatchByIds",method = RequestMethod.POST)
//    public RspResult<TestSelectBatchByIdsRspDto> selectBatchByIds(@Validated @RequestBody TestSelectBatchByIdsReqDto reqDto){
//        TestSelectBatchByIdsReqModel reqModel=TestControllerConverter.convertDtoToModel(reqDto);
//        TestSelectBatchByIdsRspModel rspModel=testService.selectBatchByIds(reqModel);
//        TestSelectBatchByIdsRspDto rspDto=TestControllerConverter.convertModelToDto(rspModel);
//        return returnRspResult(rspDto);
//    }

    @ApiOperation(value = "分页查询多条记录", notes = "分页查询多条记录", httpMethod = "POST")
    @RequestMapping(value = "/selectPage",method = RequestMethod.POST)
    public RspResult<UserInfoSelectPageRspDto> selectPage(@Validated @RequestBody UserInfoSelectPageReqDto reqDto){
        UserInfoSelectPageReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserInfoSelectPageRspModel rspModel=userInfoService.selectPage(reqModel);
        UserInfoSelectPageRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "用户登录校验", notes = "用户登录校验", httpMethod = "POST")
    @RequestMapping(value = "/userLogin",method = RequestMethod.POST)
    public RspResult<UserLoginRspDto> userLogin(@Validated @RequestBody UserLoginReqDto reqDto){
        UserLoginReqModel reqModel=UserInfoControllerConverter.convertDtoToModel(reqDto);
        UserLoginRspModel rspModel=userInfoService.userLogin(reqModel);
        UserLoginRspDto rspDto=UserInfoControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "用户登出", notes = "用户登出", httpMethod = "GET")
    @RequestMapping(value = "/userLogout",method = RequestMethod.GET)
    public RspResult userLogout(){
        HttpSession session=WebUtil.getSession();
        session.invalidate();
        return RspResult.SUCCESS;
    }

}
